<?php

class ProfileController extends Controller
{
	public function actionEdit()
	{
		$matric_no = Yii::app()->user->userModel->matric_no;
		$criteria = new CDbCriteria;
		$criteria->condition = "matric_no = '$matric_no'";
		$user_model = Resident::model()->find($criteria);
		
		if(isset($_POST['Resident']))
		{
			$model=$user_model;
			$model->attributes=$_POST['Resident'];
			if($model->save())
				$this->redirect(array('index'));
			else{
				$this->render('edit',array(
						'model'=>$user_model,
				));
			}
				
		}else{
		
		$this->render('edit',array(
			'model'=>$user_model,
		));
		
		}
		
		
		
	}

	public function actionIndex()
	{
		$matric_no = Yii::app()->user->userModel->matric_no;
		$criteria = new CDbCriteria;
		$criteria->condition = "matric_no = '$matric_no'";
		$user_model = Resident::model()->find($criteria);
		$this->render('index',array(
			'data'=>$user_model,
		));
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}